﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyProgram
{
    public partial class FrmExamCalendarEdit : Form
    {
        public FrmExamCalendarEdit()
        {
            InitializeComponent();
        }

        public static int ID;
        
        MyDB.MedicareDataClassesDataContext DB = new MyDB.MedicareDataClassesDataContext();
        private void FrmCalenderEdit_Load(object sender, EventArgs e)
        {
            comboBox1.DataSource = DB.Situations.Select(n => n);
            comboBox1.DisplayMember = "狀態名稱";
            comboBox1.ValueMember = "狀態ID";
            comboBox2.DataSource = DB.ExamConsequences.Select(n => n);
            comboBox2.DisplayMember = "檢驗結果";
            comboBox2.ValueMember = "檢驗結果ID";
            行事曆IDTextBox.Text = ID.ToString();
            var q =DB.View_ExamCalendars.Where(n => n.行事曆ID == ID).First();
            病患姓名TextBox.Text= q.病患姓名;
            comboBox1.Text = q.狀態;
            comboBox2.Text = q.檢驗結果;
            結果值TextBox.Text = q.結果值;
            備註TextBox.Text = q.備註;
        }

        private void button1_Click(object sender, EventArgs e)
        {
           DB.ExamCalendars.Where(n => n.行事曆ID == ID).First().狀態ID=(int)comboBox1.SelectedValue;
           DB.ExamCalendars.Where(n => n.行事曆ID == ID).First().檢驗結果ID = (int)comboBox2.SelectedValue;
           DB.ExamCalendars.Where(n => n.行事曆ID == ID).First().結果值 = 結果值TextBox.Text;
           DB.ExamCalendars.Where(n => n.行事曆ID == ID).First().備註 = 備註TextBox.Text;
           DB.SubmitChanges();

           MyClassLibrary.ClsRecord.Record(sender, "FrmExamCalendarEdit", DB.ExamCalendars.Where(n => n.行事曆ID == ID).First().ExamSchedule.Diagnosis.RegisterInformation.Patients.病患ID);
           this.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
